import { defineStore } from 'pinia'
import { getSeatListApi,PostSeatListApi ,postUpdateSeatApi,deleteSeatApi} from '@/api/table-manage'

export const TableseatStore = defineStore('tableseatStore', {
	state: () => {
		return {
			list: [{}],
			seatList:[],
		}
	},
	getters: {
		
	},
	actions:{
		async SaveseatList(form:any){
			if(form._id){
				await postUpdateSeatApi(form)
			}else{
			  await PostSeatListApi(form)
			}
		},
		async	getseatList(){
			const { data } = await getSeatListApi({})
			console.log(data);
			this.list = data
			const newlist = [];
			this.list.forEach(v => {
				newlist.push({
					value:v.position,
					label:v.position
				})
			})
			this.seatList = newlist
		},
		async DeleteSeat(_id:string) {
		    await deleteSeatApi({ _id })
		}
	},
})